package com.concerneyes.mine.TabActivity.serviceCentre;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.concerneyes.R;
import com.concerneyes.mine.Task.ExtensionImpl;
import com.concerneyes.mine.Task.ExtensionListener;
import com.concerneyes.mine.adapter.serviceCentre.CommonProblemAdapter;
import com.concerneyes.mine.model.MyServiceCentreModel;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.List;

import common.AbsActivity;
import http.JsonMap;
import http.Url;
import util.ActivityUtil;

import static com.concerneyes.R.id.lv_server_center;

/**
 * 常见问题
 */

public class CommonProblem extends AbsActivity implements AdapterView.OnItemClickListener, ExtensionListener {
    private ListView lvlist;
    private CommonProblemAdapter adapter;
    private ExtensionImpl impl;
    private String title;

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_serivce_centre);
        title = getIntent().getExtras().getString("title");
        setTitle(title);
        initView();
    }

    private void initView() {
        lvlist = (ListView) findViewById(lv_server_center);
        lvlist.setOnItemClickListener(this);
        impl = new ExtensionImpl(this);
        impl.extensionImpl(Url.FaqList);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        int itemId = adapter.getItem(position).getId();
        String content = adapter.getItem(position).getContent();
        ActivityUtil.detailIntent(this, itemId, title,content);
    }

    @Override
    public void onExtensionSuccess(List<JsonMap> data) {
        String datas = data.toString();
        try {
            List<MyServiceCentreModel> models = new Gson().fromJson(datas, new TypeToken<ArrayList<MyServiceCentreModel>>() {
            }.getType());
            adapter = new CommonProblemAdapter(CommonProblem.this, false, models);
            lvlist.setAdapter(adapter);
        } catch (Exception e) {
        }
    }

    @Override
    public void onExtensionFail() {

    }
}
